﻿using System.Collections.Generic;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Collections;
using System.Data;
using System.Linq;

namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {

        /// <summary>
        /// GetJob is used to collect the tasks to finish the order creation
        /// </summary>
        /// <param name="FInterID"></param>
        /// <returns></returns>
        public DataSet KWTWBLABLE(DataSet db)
        {

            ArrayList tbs = new ArrayList() { "A", "B", "C" };
            string a = (string)tbs[0];
            DataSet Result = new DataSet();
            DataSet Return = new DataSet();

            try
            {
                string processed = ""; 
               
                foreach (DataRow dwWB in db.Tables["WBBST"].Rows)
                {
                    #region
                    //string PACKNR = dwWB["WBBPACKNR"].ToString();
                    //if (PACKNR == "0000")
                    //    continue; 
                    //string STKNR = dwWB["WBBSTKNR"].ToString().Trim();
                    //if (processed.Contains(STKNR + ";"))
                    //    continue;
                    
                    //#region=====空白文档=======
                    //DestFile = destfolder + "\\" + STKNR + ".xls";
                    //if (System.IO.File.Exists(DestFile))
                    //{
                    //    System.IO.File.Delete(DestFile);
                    //}
                    //System.IO.File.Copy(strExcelFile, DestFile);
                    //exAgent.Open(DestFile); 
                    //#endregion
                    //processed += STKNR + ";";
                    //exAgent.RangeReplace(1, 40, "#designno#", dwWB["WBBART"].ToString().Trim());
                    //double LENG = Convert.ToDouble(dwWB["WBBISTKLG"].ToString()) / 1000;
                    //exAgent.RangeReplace(1, 40, "#length#", Helpers.Helper.RoundX(LENG, 10).ToString());
                    //exAgent.RangeReplace(1, 40, "#lengthyds#", Helpers.Helper.RoundX(LENG / 0.9144, 10).ToString());
                    //exAgent.RangeReplace(1, 40, "#coilno#", dwWB["WBBPACKNR"].ToString().Trim());
                    //exAgent.RangeReplace(1, 40, "#lot#", dwWB["WBBTAX"].ToString().Trim());
                    //exAgent.SetCellValue(28, 1, "*" + STKNR + "*");
                    //if (exAgent.strExcelFile.Contains("coillabel"))
                    #endregion
                    exAgent.SetCellValue(3, 3, Helpers.Helper.GetGB2312Value(dwWB["WBBFILLER"].ToString().Trim()));
                    exAgent.SetCellValue(4, 3, Helpers.Helper.GetGB2312Value(dwWB["WBBART"].ToString().Trim()));
                    exAgent.SetCellValue(5, 3, Helpers.Helper.GetGB2312Value(dwWB["WBBDPART"].ToString().Trim() + dwWB["WBBDPART2"].ToString().Trim()));
                    exAgent.SetCellValue(6, 3, dwWB["WBBNEUDAT"].ToString().Trim());
                    exAgent.SetCellValue(7, 3, (Convert.ToDouble(dwWB["WBBSSTKLG"].ToString())*0.001).ToString().Trim());
                    processed = dwWB["WBBZENSURKZ"].ToString().Trim();
                    if (processed=="A")
                    {
                        processed = "1";
                    }
                    if (processed == "B")
                    {
                        processed = "2";
                    }
                    if (processed == "C")
                    {
                        processed = "3";
                    }
                    if (processed == "D")
                    {
                        processed = "4";
                    }
                    exAgent.SetCellValue(7, 5, dwWB["WBBZMT"].ToString().Trim()+"-"+processed);
                    exAgent.SetCellValue(8, 3, dwWB["WBBKOMMNR"].ToString().Trim());
                    exAgent.SetCellValue(8, 5, dwWB["WBBNEUBEN"].ToString().Trim());
                    exAgent.SetCellValue(9, 2, "*" + dwWB["WBBSTKNR"].ToString().Trim() + "*");
                    exAgent.Save();
                    exAgent.FileName = DestFile;
                    DirectPrint(DestFile); 
                } 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {

            }
            return Return;
        }

    }
}
